package org.pausd.gunn.compsci;

import java.io.BufferedReader;
import java.io.InputStreamReader;


/**
 * The client-side instance of Player, handles graphics and user input
 * @author CodyS
 *
 */
public class LocalPlayer extends Player {
	private BufferedReader br;
	public LocalPlayer(Game g) {
		super(g);
		br = new BufferedReader(new InputStreamReader(System.in));
	}
	/**
	 * Ask the user for a number then add that to the counter
	 */
	public void doTurn() {
		try {
			System.out.println("Your turn! Enter a number to add to the counter:");
			int add = Integer.parseInt(br.readLine());
			getGame().addToCounter(add);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * Ask the user if he/she is ready, annoy them until they are
	 */
	public void ready() {
		System.out.println("Say \"ready\" when ready to start.");
		try {
			while(!br.readLine().equals("ready")) {
				System.out.println("Say \"ready\" when ready to start.");
			}
			getGame().playerReady(this);
		}
		catch(Exception e) {
			e.printStackTrace();
		}
	}
	@Override
	public void leave() {
		System.out.println("Could no longer be in game.");
		System.exit(0);
	}
	@Override
	/**
	 * Notify the player what the counter is.
	 */
	public void counter(int num) {
		System.out.println("Counter is "+num);
	}
	@Override
	/**
	 * Notify the player that the game has started.
	 */
	public void started() {
		System.out.println("Game started");
	}
}
